package pl.olap.dao;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;

@Entity
@Table(name = "movie")
public class Movie extends BaseEntity {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private static final int NORMAL_LENGTH = 255;
	private static final int DESCRIPTION_LENGTH = 4000;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(updatable = false, name = "MOVIE_ID")
	private Integer idMovie;

	@Column(length = 255, nullable = true)
	private String title;
	
	
	@Column(precision = 3, nullable = true)
	private Float rating;

	@Column(length = 4000, nullable = true)
	private String description;
   
  @Column(nullable = true)
  @Temporal(TemporalType.TIMESTAMP)
  private Date createDate; 
  
  @Column(length = 255, nullable = true)
  private String site;
	
	@OneToOne(fetch = FetchType.EAGER)
	@PrimaryKeyJoinColumn
	private Premiere premiere;

	@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.REFRESH)
	@org.hibernate.annotations.Fetch(org.hibernate.annotations.FetchMode.SUBSELECT)
	private List<Person> persons;
	
	@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.REFRESH)
	@JoinTable(name = "movie_genre", joinColumns = 
	{ @JoinColumn(name = "MOVIE_ID", nullable = false, updatable = false) }, inverseJoinColumns = 
	{ @JoinColumn(name = "GENRE_ID", nullable = false, updatable = false) })
	@org.hibernate.annotations.Fetch(org.hibernate.annotations.FetchMode.SUBSELECT)
	private List<Genre> genres;
	
	@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.REFRESH)
	@org.hibernate.annotations.Fetch(org.hibernate.annotations.FetchMode.SUBSELECT)
	@JoinTable(name = "movie_production", joinColumns = 
	{ @JoinColumn(name = "MOVIE_ID", nullable = false, updatable = false) }, inverseJoinColumns = 
	{ @JoinColumn(name = "PRODUCTION_ID", nullable = false, updatable = false) })
	private List<Production> productions;

	/**
	 * @return the premiere
	 */
	public Premiere getPremiere() {
		return premiere;
	}

	/**
	 * @return the productions
	 */
	public List<Production> getProductions() {
		return productions;
	}

	/**
	 * @param premiere the premiere to set
	 */
	public void setPremiere(Premiere premiere) {
		this.premiere = premiere;
	}

	/**
	 * @param productions the productions to set
	 */
	public void setProductions(List<Production> productions) {
		this.productions = productions;
	}

	public Movie() {
	}
	
  public Date getCreateDate() {
		return createDate;
	}

	public void setCreateDate(Date createDate) {
		this.raticreateDateng = createDate;
	}

	public Float getRating() {
		return rating;
	}

	public void setRating(Float rating) {
		this.rating = rating;
	}

	public Integer getIdMovie() {
		return this.idMovie;
	}

	public void setIdMovie(Integer idMovie) {
		this.idMovie = idMovie;
	}
   
  public String getSite() {
		return this.site;
	}

	public void setSite(String site) {
		this.site = site;
	}

	public String getTitle() {
		return this.title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public void setPersons(List<Person> persons) {
		this.persons = persons;
	}

	public List<Person> getPersons() {
		return persons;
	}

	public void setGenres(List<Genre> genres) {
		this.genres = genres;
	}

	public List<Genre> getGenres() {
		return genres;
	}
}
